package queryfish.google.search;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.UnknownHostException;

public class CheckConnection {
	public static boolean flagConnection;

	public static boolean isInternetReachable() {
		try {

			// make a URL to a known source
			URL url = new URL("http://www.google.com");

			// open a connection to that source
			HttpURLConnection urlConnect = (HttpURLConnection) url
					.openConnection();

			// trying to retrieve data from the source. If there
			// is no connection, this line will fail
			Object objData = urlConnect.getContent();

		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
			return flagConnection = false;

		} catch (IOException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
			return flagConnection = false;
		}
		return flagConnection = true;

	}

}
